package com.usian.controller;

import com.usian.pojo.dep.Dep;
import com.usian.pojo.staff.Staff;
import com.usian.service.DepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/dep")
public class DepController {
    @Autowired
    private DepService depService;


    @RequestMapping("/als")
    public String all(Model model){
        List<Dep> dlist = depService.dlist();
        model.addAttribute("dlist",dlist);
        return "alls";
    }

    @RequestMapping("/toUser")
    public String toUser(){
        return "ad1";
    }

    @PostMapping("/ad1")
    public String ad(Dep dep){
        dep.setCreationTime(new Date());
        depService.ad(dep);
        return "redirect:/dep/als";
    }




    @RequestMapping("/dele")
    public String dele(Integer did){
        depService.dele(did);
        return "redirect:/dep/als";
    }
}
